package com.store.practice.controller;

import com.store.practice.common.api.CommonResult;
import com.store.practice.dto.OrderInsertParam;
import com.store.practice.model.BgAppointmentOrder;
import com.store.practice.service.MemberInfoManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Api(tags = "MemberInfoManageController",description = "会员操作管理")
@RequestMapping("/member")
@RestController
public class MemberInfoManageController {
    @Autowired
    private MemberInfoManageService memberInfoManageService;

    @ApiOperation("选择门店展示门店首页")
    @GetMapping("/getHome")
    public CommonResult getHome(Integer storeId){
        Map result = memberInfoManageService.getHome(storeId);
        if (result==null){
            return CommonResult.failed();
        }
        return CommonResult.success(result);
    }

    @ApiOperation("门店介绍")
    @GetMapping("/getStoreInfo")
    public CommonResult getStore(Integer storeId){
        Map result = memberInfoManageService.getStore(storeId);
        if (result!=null){
            return CommonResult.success(result);
        }
        return CommonResult.failed();
    }

    @ApiOperation("展示门店美容师列表")
    @GetMapping("/getStaff")
    public CommonResult getStaff(Integer storeId){
        List<Map> result = memberInfoManageService.getStaff(storeId);
        if (result!=null){
            return CommonResult.success(result);
        }
        return CommonResult.failed();
    }

    @ApiOperation("新增预约")
    @PostMapping("/insertOrder")
    public CommonResult insertOrder(@RequestBody BgAppointmentOrder order){
        int i = memberInfoManageService.insertOrder(order);
        if (i>0){
            return CommonResult.success(i);
        }
        return CommonResult.failed();
    }

    @ApiOperation("显示预约当天已预约和已过时间段")
    @GetMapping("/getTime")
    public CommonResult getTime(@RequestParam("serviceDate") @DateTimeFormat(pattern = "yyyy-MM-dd") Date serviceDate,
                                Integer storeId){
        Map result = memberInfoManageService.getTime(serviceDate, storeId);
        if (result!=null){
            return CommonResult.success(result);
        }
        return CommonResult.failed();
    }


}
